<template>
    <div class="tab1">
        <Form :label-width="160" inline :disabled="true">
            <table style="width:100%;">
                <tr>
                    <td style="width:26%;" colspan="2">
                        <FormItem label="申请人证件号码" prop="azcp0001">
                            <Input v-model="data.azcp0001" placeholder="" @on-blur="loadExistData()"
                                   class="itemStyle"/>
                        </FormItem>
                    </td>
                    <td style="width:29%;" colspan="2">
                        <FormItem label="申请人证件类型" prop="azcp0002">
                            <dictSelect :sel_val='data.azcp0002' dictCode="certificatetype"
                                        :bindData.sync="data.azcp0002" showKeys="1" class="itemStyle"/>
                        </FormItem>
                    </td>
                    <td style="width:29%;" colspan="2">
                        <FormItem label="申请人姓名" prop="azcp0003">
                            <Input v-model="data.azcp0003" placeholder="" class="itemStyle"/>
                        </FormItem>
                    </td>
                    <td style="width:13%;" rowspan="4">
                        <img :src="data.azcp0519" class="dbhead-img"/>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <FormItem label="户籍地行政区划" prop="azdf0006">
                            <area-linkage :areaCode.sync="data.azdf0006" :countyDisable=true :streetDisable=true
                                          :communityDisable=true></area-linkage>
                        </FormItem>
                    </td>
                    <td colspan="2">
                        <FormItem label="户籍地邮政编码" prop="azdf0009">
                            <Input v-model="data.azdf0009" placeholder="" class="itemStyle"/>
                        </FormItem>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <FormItem label="户籍地详细地址" prop="azdf0500">
                            <Input v-model="data.azdf0500" placeholder="" class="itemLongStyle"/>
                        </FormItem>
                    </td>
                    <td colspan="2">
                        <FormItem label="常住地邮政编码" prop="azdf0502">
                            <Input v-model="data.azdf0502" placeholder="" class="itemStyle"/>
                        </FormItem>
                    </td>
                </tr>
                <tr>
                    <td colspan="6">
                        <FormItem label="是否本市居住" prop="azdf0505">
                            <c-dict-select v-model="data.azdf0505" dictCode="yesorno" :width="180"/>
                        </FormItem>
                    </td>
                </tr>
                <tr v-if="data.azdf0505=='0'">
                    <td colspan="6">
                        <FormItem label="外市居住区划" prop="azdf0507">
                            <Ss01003Tag :bindshengjiData.sync="data.azdf0506"
                                        :bindshijiData.sync="data.azdf0507"
                                        :shengji_value="data.azdf0506"
                                        :shiji_value="data.azdf0507"
                                        style="width: 180px">
                            </Ss01003Tag>
                        </FormItem>
                    </td>
                </tr>
                <tr v-if="data.azdf0505=='1'">
                    <td colspan="4">
                        <FormItem label="常住地行政区划" prop="azdf0501">
                            <area-linkage :areaCode.sync="data.azdf0501" :countyDisable=true :streetDisable=true
                                          :communityDisable=true></area-linkage>
                        </FormItem>
                    </td>
                    <td colspan="2">
                        <FormItem label="居住地类型" prop="azdf0512">
                            <c-dict-select v-model="data.azdf0512" dictCode="live_type" :width="180"/>
                        </FormItem>
                    </td>
                </tr>
                <tr v-if="data.azdf0512=='01'&&data.azdf0505=='1'">
                    <td style="width:26%;" colspan="2">
                        <FormItem label="小区名称" prop="azdf0513">
                            <Input v-model="data.azdf0513" placeholder="" class="itemStyle" maxlength="20"/>
                        </FormItem>
                    </td>
                    <td style="width:29%;" colspan="2">
                        <FormItem label="楼栋号" prop="azdf0514">
                            <Input v-model="data.azdf0514" placeholder="请输入楼栋号" class="itemStyle" maxlength="20"/>
                        </FormItem>
                    </td>
                    <td style="width:29%;" colspan="3">
                        <FormItem label="户室门牌号" prop="azdf0515">
                            <Input v-model="data.azdf0515" placeholder="请输入户室门牌号" class="itemStyle" maxlength="20"/>
                        </FormItem>
                    </td>
                </tr>
                <tr v-if="data.azdf0512=='02'&&data.azdf0505=='1'">
                    <td style="width:29%;" colspan="7">
                        <FormItem label="村小组号" prop="azdf0516">
                            <Input v-model="data.azdf0516" placeholder="请输入村小组号" class="itemStyle" maxlength="20"/>
                        </FormItem>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <FormItem label="常住地详细地址" prop="azdf0008">
                            <Input v-model="data.azdf0008" placeholder="" class="itemLongStyle"/>
                        </FormItem>
                    </td>
                    <td colspan="2">
                        <FormItem label="联系人类型" prop="azdf0510">
                            <c-dict-select v-model="data.azdf0510" dictCode="contact_type" :width="180"/>
                        </FormItem>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <FormItem label="所属地行政区划" prop="azdf0007">
                            <area-linkage :areaCode.sync="data.azdf0007" :countyDisable=true :streetDisable=true
                                          :communityDisable=true></area-linkage>
                        </FormItem>
                    </td>
                    <td colspan="3">
                        <FormItem label="联系人姓名" prop="azdf0511">
                            <Input v-model="data.azdf0511" placeholder="请输入联系人姓名" class="itemStyle"/>
                        </FormItem>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <FormItem label="是否有非保障人员" prop="ssca0087">
                            <dictSelect :sel_val='data.ssca0087' dictCode="yesorno" :bindData.sync="data.ssca0087"
                                        class="itemStyle"/>
                        </FormItem>
                    </td>
                    <td colspan="2">
                        <FormItem label="是否有赡(抚、扶)养人" prop="ssca0088">
                            <dictSelect :sel_val='data.ssca0088' dictCode="yesorno" :bindData.sync="data.ssca0088"
                                        class="itemStyle"/>
                        </FormItem>
                    </td>
                    <td colspan="3">
                        <FormItem label="联系方式" prop="azdf0011">
                            <Input v-model="data.azdf0011" placeholder="" class="itemStyle"/>
                        </FormItem>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <FormItem v-if="(data.ssca0002=='101')||(data.ssca0002=='201') " label="保障标准类型" prop="ssca0079">
                            <dictSelect :sel_val='data.ssca0079' dictCode="alonemoneytype" :bindData.sync="data.ssca0079"
                                        class="itemStyle"/>
                        </FormItem>
                    </td>
                </tr>
            </table>
        </Form>
        <div style="height:40px;line-height:40px;margin-top:10px;text-align: center ">
            <Button type="primary" @click="nextStep('data')" :loading="btnLoading"
                    style="margin-left:20px">下一步
            </Button>
        </div>
    </div>
</template>

<script>
    import dictSelect from '@/components/dictSelect/dictSelect.vue'
    import {postAction} from '@/api/request'
    import pic_header from '@/assets/images/header.jpeg'
    import Ss01003Tag from '@/components/system/ss01003-select'// 户籍区划功能

    export default {
        name: 'application1',
        components: {
            dictSelect,
            Ss01003Tag
        },
        data() {
            return {
                currentTab: 0,
                familyInfo: {},
                data: {
                    azcp0002: '',
                    azcp0003: '',
                    azdf0006: '',
                    // azdf0010: '',
                    azdf0011: '',
                    azdf0500: '',
                    azdf0501: '',
                    azdf0007: '',
                    azdf0008: '',
                    ssca0002: '',
                    ssca0087: '',
                    ssca0088: '',
                    azcp0001: '',
                    azcp0519: pic_header,
                    azcp0578: '0', //是否通过低保事前验证  0否  1是
                    ss17001Id: '',
                    ss17002Id: '',
                    ss12001Id: '',
                    azdf0510: '',
                    azdf0511: '',
                },
                url: {
                    submit: '/api/ac/subsistence/ss17001Service/createDb17Step1Submit',
                    load: '/api/ac/subsistence/ss17000Service/updateSs17001Data',
                },
                btnLoading: false,
            }
        },
        methods: {
            edit(record) {
            },
            loadStep1Data(data) { //从后面步骤返回第一步时调用
                let that = this
                let url = that.url.load
                that.familyInfo = data
                let dataParam = {}
                dataParam.azcp0001 = data.azcp0001
                dataParam.ss12001Id = data.ss12001Id
                dataParam.ss16001Id = data.ssca0001
                dataParam.ssca0002 = that.$parent.familyInfo.ssca0002
                dataParam.bgType = that.$parent.familyInfo.ssca0016
                that.Loading = true
                postAction(url, dataParam).then((res) => {
                    if (res.data.data) {
                        if (res.data.data.code == 1) {
                            let record = res.data.data.data
                            that.data = Object.assign({}, record)
                            if (that.data.azcp0519 == null) {
                                that.data.azcp0519 = pic_header
                            }
                            if (that.data.azcp0578 == '1') { //已完成验证
                                that.validateStatus = false
                            } else {
                                that.validateStatus = true
                            }
                            that.$Message.success(res.data.data.msg)
                            //如是停救、迁移,页面不可编辑
                            if (that.$parent.familyInfo.ssca0016 == '300' || that.$parent.familyInfo.ssca0016 == '500' || that.$parent.familyInfo.ssca0016 == '501') {
                                that.disabledForStop = true
                                that.validateStatus = false
                                that.data.azcp0578 = '1'
                            }

                        } else {
                            that.$Message.error(res.data.data.msg)
                        }
                    } else {
                        that.$Message.error(res.data.errmsg)
                    }
                    console.log("then end");
                }).finally(() => {
                    console.log("finally end");
                    that.Loading = false
                })
            },
            async nextStep(name) {
                let that = this
                that.btnLoading = true
                let dataParam = {}
                dataParam = Object.assign({}, that.data)
                let url = that.url.submit
                //变更类型
                dataParam.handleType = that.$parent.familyInfo.ssca0016
                dataParam.renewSs12001 = '0'
                postAction(url, dataParam).then((res) => {
                    if (res.data.data) {
                        if (res.data.data.code == 1) {
                            let info = res.data.data
                            that.$Message.success(res.data.data.msg)
                            that.$parent.familyInfo.prsnid = info.data.prsnid
                            that.$parent.familyInfo.ss12001Id = info.data.ss12001Id
                            that.$parent.familyInfo.ss17001Id = info.data.id
                            //针对类型转换，如果当前存储救助类型不等于返回类型，更新存储
                            if (that.$parent.familyInfo.ssca0002 != info.data.ssca0002) {
                                that.$parent.familyInfo.ssca0002 = info.data.ssca0002
                            }
                            that.$parent.familyInfo.ssca0087 = that.data.ssca0087
                            that.$parent.familyInfo.ssca0088 = that.data.ssca0088
                            that.familyInfo.azdf0007 = that.data.azdf0007
                            that.$emit('nextStep', that.familyInfo)
                            // this.$parent.clickStep(1);
                        } else {
                            that.$Message.error(res.data.data.msg)
                        }
                    } else {
                        that.$Message.error('数据交互异常')
                    }
                }).finally(() => {
                    that.btnLoading = false
                })
            },
            setAreaState() {
                let that = this
                let url = that.url.areaInfo
                let dataParam = {}
                that.Loading = true
                postAction(url, dataParam).then((res) => {
                    if (res.data.data) {
                        if (res.data.data.code == 1) {
                            let record = res.data.data.data
                            let arealevel = record.arealevel
                            if (arealevel == 4) {
                                that.countyState = true
                                that.streetState = true
                                that.communityState = true
                            } else if (arealevel == 3) {
                                that.countyState = true
                                that.streetState = true
                                that.communityState = false
                            } else if (arealevel == 2) {
                                that.countyState = true
                                that.streetState = false
                                that.communityState = false
                            }
                        } else {
                        }
                    } else {
                        that.$Message.error('数据交互异常，个人属地信息载入异常')
                    }
                }).finally(() => {
                    that.Loading = false
                })
            },
        },
        mounted() {
            let that = this
            let params = that.$parent.familyInfo
            if (typeof (params.azcp0001) != 'undefined') {
                that.loadStep1Data(params)
            } else {
                that.$refs['data'].resetFields()
            }
        },
        watch: {},
        created() {
            this.setAreaState()
        }
    }

</script>

<style scoped>
    .dbhead-img {
        height: 160px;
        width: 120px;
        margin-left: 10px;
    }

    /deep/ .ivu-form-item-error-tip {
        display: none;
    }

    .ivu-form-item {
        margin-bottom: 0px;
    }

    .itemStyle {
        width: 180px
    }

    .itemLongStyle {
        width: 450px
    }
</style>
